package com.humngyang.com.hmy.service;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.humngyang.com.hmy.entity.Authority;
import com.humngyang.com.hmy.mapper.AuthorityMapper;
import com.humngyang.com.hmy.utils.TreeUtile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.*;

@Service
public class AuthorityService {


    @Autowired
    AuthorityMapper authorityMapper;

    /**
     * Author : hmy
     *
     * @date 2020/2/25 22:11
     * describution : 查询所有的权限列表
     **/

    public List<Authority> getAllAuthrority() {
        List<Authority> authorityList = authorityMapper.selectList(null);
        if (CollectionUtils.isEmpty(authorityList)) {
            return Collections.EMPTY_LIST;
        } else {
            return authorityList;
        }
    }

    public List<Map<String,Object>> getAllAuthrorityMap() {
        List<Map<String,Object>> authority = authorityMapper.selectMaps(null);
        if (CollectionUtils.isEmpty(authority)) {
            return Collections.EMPTY_LIST;
        } else {
            return authority;
        }
    }
    public List<Map<String, Object>> getTreeAuthrority() {
        List<Map<String,Object>> allAuthrority = getAllAuthrorityMap();
        List<Map<String, Object>> maps =TreeUtile.parseTree(allAuthrority);
        return maps;
    }
}
